class Valleyers::Show::AlbumsController < ApplicationController
  def show
    @valleyer = Valleyer.find params[:id]
  end
  
  def new
    @album = Album.new :author_id => current_valleyer_id
  end

  def create
    @album = Album.new params[:album]
    if params[:document_type][:name].blank?
      @album.documet_type = DocumetType.find_by_name "未分类"
    else
      @documet_type = DocumetType.find_by_name params[:document_type][:name]
      if @documet_type.nil?
        @album.documet_type = DocumetType.new :name => params[:document_type][:name],
          :valleyer_id => current_valleyer_id
        @album.documet_type.save
      else
        @album.documet_type = @documet_type
      end
    end
    @album.save
    @valleyer = current_valleyer
  end

  def edit
    @album = Album.find params[:id]
    @document_type = @album.documet_type
  end

  def update
    @album = Album.find params[:id]
    if params[:document_type][:name].blank?
      @album.documet_type = DocumetType.find_by_name "未分类"
    else
      @documet_type = DocumetType.find_by_name params[:document_type][:name]
      if @documet_type.nil?
        @album.documet_type = DocumetType.new :name => params[:document_type][:name],
          :valleyer_id => current_valleyer_id
        @album.documet_type.save
      else
        @album.documet_type = @documet_type
      end
    end
    render :edit unless @album.update_attributes params[:album]
    @valleyer = current_valleyer
  end

  def destroy
    @album = Album.find params[:id]
    @album.destroy
    @valleyer = current_valleyer
  end

  def authorize

  end
end
